package entity

import (
	"shqsoft.cn/pasnj/base"
	//"strconv"
	"time"

	"github.com/jinzhu/gorm"
)

//对公存贷款批量
type CompAccoDiviPl struct {
	ID          int        `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	DSDT        *time.Time `gorm:"column:DSDT";type:date` //日期
	ENCD        string     `gorm:"column:ENCD"`
	CUNM        string     `gorm:"column:CUNM"`         //客户名称
	ACNO        string     `gorm:"column:ACNO"`         //账号
	BANO        string     `gorm:"column:BANO;size:10"` //子账号
	KHJL1       string     `gorm:"column:KHJL1"`        //客户经理1
	ZB1         *float32   `gorm:"column:ZB1"`          //占比1
	KHJL2       string     `gorm:"column:KHJL2"`        //客户经理2
	ZB2         *float32   `gorm:"column:ZB2"`          //占比2
	KHJL3       string     `gorm:"column:KHJL3"`        //客户经理3
	ZB3         *float32   `gorm:"column:ZB3";`         //占比3
	KHJL4       string     `gorm:"column:KHJL4"`        //客户经理4
	ZB4         *float32   `gorm:"column:ZB4";`         //占比4
	KHJL5       string     `gorm:"column:KHJL5"`        //客户经理5
	ZB5         *float32   `gorm:"column:ZB5";`         //占比5
	KHJL6       string     `gorm:"column:KHJL6"`        //客户经理6
	ZB6         *float32   `gorm:"column:ZB6";`         //占比6
	KHJL7       string     `gorm:"column:KHJL7"`        //客户经理7
	ZB7         *float32   `gorm:"column:ZB7";`         //占比7
	KHJL8       string     `gorm:"column:KHJL8"`        //客户经理8
	ZB8         *float32   `gorm:"column:ZB8";`         //占比8
	KHJL9       string     `gorm:"column:KHJL9"`        //客户经理9
	ZB9         *float32   `gorm:"column:ZB9";`         //占比9
	KHJL10      string     `gorm:"column:KHJL10"`       //客户经理10
	ZB10        *float32   `gorm:"column:ZB10";`        //占比10
	DRJG        string     `gorm:"column:DRJG"`         //导入结果
	ISTZ        string     `gorm:"column:ISTZ"`         //是否认定批量调整
	ISTZCaption string     `gorm:"-"`
}

//TableName 对私贷款认定分户情况
func (CompAccoDiviPl) TableName() string {
	return "T_COMP_ACCO_PL_DTIP"
}
func (pl *CompAccoDiviPl) AfterFind() (err error) {
	if pl.ISTZ == "0" {
		pl.ISTZCaption = "批量处理未分配的对公客户"
	} else if pl.ISTZ == "1" {
		pl.ISTZCaption = "批量调整已分配的对公客户"
	}
	return
}

//导入时验证导入的占比是否为100%
func compAccoAfterValidation(index int, rowdatas []string) []base.ErrorData {
	return nil
}

//导入后执行分户处理
func compAccoAfterImport(tx *gorm.DB, params map[string]string) (err error) {

	ISTZ := params["ISTZ"]
	if ISTZ == "0" {
		tx.Exec("exec UP_COMP_DIVI_PL_CL")
	} else if ISTZ == "1" {
		tx.Exec("exec UP_COMP_DIVI_PL_TZ")
	}
	return nil
}

func CompAccoDiviPlEF() base.EntityFunc {
	return func() interface{} {
		entity := CompAccoDiviPl{}
		return &entity
	}
}

func CompAccoDiviPlESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []CompAccoDiviPl
		return &entities
	}
}

func init() {

	base.DaoPoolObj.Put("CompAccoDiviPl", base.NewDefaultDao(CompAccoDiviPlEF(), CompAccoDiviPlESF(), nil))
	base.SetValidationCallBack("compAccopl", compAccoAfterValidation)
	base.SetAfterCallBack("compAccopl", compAccoAfterImport)
}
